/**
 * https://leetcode-cn.com/problems/combinations/
 * @param {number} n
 * @param {number} k
 * @return {number[][]}
 */
 var combine = function(n, k) {
  const allSet = new Array(n);
  for (let i = 0; i < n; i++) {
      allSet[i] = i + 1;
  }
  const results = [];
  function dfs(current, left) {
      // terminator
      if (current.length === k) {
          results.push([...current]);
          return;
      }
      for (let i = 0; i < left.length; i++) {
          current.push(left[i]);
          // drill down
          dfs(current, left.slice(i + 1));
          // process result
          current.pop()
      }
  }
  dfs([], allSet);
  return results;
};
